<?php
session_start();
header("Content-type: text/html; charset=utf-8"); 

include_once($_SERVER['DOCUMENT_ROOT']."/common/config.php");
// $_conn = connect_mysql('wechat_grade');

function is_not_json($str){ 
	return is_null(json_decode($str));
}

if($_GET['xh'] && $_GET['xn'] && $_GET['xq']){
	$xh = $_GET['xh'];
	$xn = $_GET['xn'];
	$xq = $_GET['xq'];
	
	if($_SESSION['pass_check'] != $xh){
		$result = Array(
			'error' => '貌似没验证密码'
		);
	}else{
		$url = "http://61.183.207.40/zjdxgc/wbwj/get_grade.asp?xh=".$xh."&year=".$xn."&term=".$xq;
		$data = file_get_contents($url);
		if(!is_not_json($data)){
			$data = json_decode($data);
			$result = Array(
				'error' => '',
				'name' => $data[0]->XM
			);
			foreach($data as $r){
				$result['grade'][] = Array(
					$r->QMCJ, $r->PSCJ, $r->SYCJ, $r->CJ, $r->KCMC, $r->XKKH
				);
			}
		}else{
			$result = Array(
				'error' => '教务处挂了2333',
			);
		}
	}
}else{
	$result = Array(
		'error' => '信息不全！',
	);
}

$json = json_encode($result);
echo $json;

?>